<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Commands::Discover</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Commands::Discover</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/railties/lib/commands/plugin_rb.html">
                vendor/rails/railties/lib/commands/plugin.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000483">extract_repository_uri</a>&nbsp;&nbsp;
      <a href="#M000479">new</a>&nbsp;&nbsp;
      <a href="#M000480">options</a>&nbsp;&nbsp;
      <a href="#M000481">parse!</a>&nbsp;&nbsp;
      <a href="#M000482">scrape</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000479" class="method-detail">
        <a name="M000479"></a>

        <div class="method-heading">
          <a href="#M000479" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(base_command)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000479-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000479-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 637</span>
637:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">base_command</span>)
638:       <span class="ruby-ivar">@base_command</span> = <span class="ruby-identifier">base_command</span>
639:       <span class="ruby-ivar">@list</span> = <span class="ruby-keyword kw">false</span>
640:       <span class="ruby-ivar">@prompt</span> = <span class="ruby-keyword kw">true</span>
641:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000483" class="method-detail">
        <a name="M000483"></a>

        <div class="method-heading">
          <a href="#M000483" class="method-signature">
          <span class="method-name">extract_repository_uri</span><span class="method-args">(uri)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000483-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000483-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 704</span>
704:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">extract_repository_uri</span>(<span class="ruby-identifier">uri</span>)
705:       <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/(svn|https?):.*\/plugins\//i</span>)[<span class="ruby-value">0</span>]
706:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000480" class="method-detail">
        <a name="M000480"></a>

        <div class="method-heading">
          <a href="#M000480" class="method-signature">
          <span class="method-name">options</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000480-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000480-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 643</span>
643:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options</span>
644:       <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
645:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">set_summary_indent</span>(<span class="ruby-value str">'  '</span>)
646:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">banner</span> =    <span class="ruby-node">&quot;Usage: #{@base_command.script_name} discover URI [URI [URI]...]&quot;</span>
647:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">define_head</span> <span class="ruby-value str">&quot;Discover repositories referenced on a page.&quot;</span>
648:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">separator</span>   <span class="ruby-value str">&quot;&quot;</span>        
649:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">separator</span>   <span class="ruby-value str">&quot;Options:&quot;</span>
650:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">separator</span>   <span class="ruby-value str">&quot;&quot;</span>
651:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">on</span>(         <span class="ruby-value str">&quot;-l&quot;</span>, <span class="ruby-value str">&quot;--list&quot;</span>, 
652:                       <span class="ruby-value str">&quot;List but don't prompt or add discovered repositories.&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-ivar">@list</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@prompt</span> = <span class="ruby-operator">!</span><span class="ruby-ivar">@list</span> }
653:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">on</span>(         <span class="ruby-value str">&quot;-n&quot;</span>, <span class="ruby-value str">&quot;--no-prompt&quot;</span>, 
654:                       <span class="ruby-value str">&quot;Add all new repositories without prompting.&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@prompt</span> = <span class="ruby-operator">!</span><span class="ruby-identifier">v</span> }
655:       <span class="ruby-keyword kw">end</span>
656:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000481" class="method-detail">
        <a name="M000481"></a>

        <div class="method-heading">
          <a href="#M000481" class="method-signature">
          <span class="method-name">parse!</span><span class="method-args">(args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000481-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000481-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 658</span>
658:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>)
659:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>)
660:       <span class="ruby-identifier">args</span> = [<span class="ruby-value str">'http://wiki.rubyonrails.org/rails/pages/Plugins'</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
661:       <span class="ruby-identifier">args</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">uri</span><span class="ruby-operator">|</span>
662:         <span class="ruby-identifier">scrape</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">repo_uri</span><span class="ruby-operator">|</span>
663:           <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:next_uri</span>) <span class="ruby-keyword kw">do</span>
664:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@prompt</span>
665:               <span class="ruby-keyword kw">begin</span>
666:                 <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Add #{repo_uri}? [Y/n] &quot;</span>
667:                 <span class="ruby-identifier">throw</span> <span class="ruby-identifier">:next_uri</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$stdin</span>.<span class="ruby-identifier">gets</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/^y?$/i</span>
668:               <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Interrupt</span>
669:                 <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">puts</span>
670:                 <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
671:               <span class="ruby-keyword kw">end</span>
672:             <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@list</span>
673:               <span class="ruby-identifier">puts</span> <span class="ruby-identifier">repo_uri</span>
674:               <span class="ruby-identifier">throw</span> <span class="ruby-identifier">:next_uri</span>
675:             <span class="ruby-keyword kw">end</span>
676:             <span class="ruby-constant">Repositories</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">repo_uri</span>)
677:             <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;discovered: #{repo_uri}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span> <span class="ruby-keyword kw">or</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@prompt</span>
678:           <span class="ruby-keyword kw">end</span>
679:         <span class="ruby-keyword kw">end</span>
680:       <span class="ruby-keyword kw">end</span>
681:       <span class="ruby-constant">Repositories</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">save</span>
682:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000482" class="method-detail">
        <a name="M000482"></a>

        <div class="method-heading">
          <a href="#M000482" class="method-signature">
          <span class="method-name">scrape</span><span class="method-args">(uri) {|uri unless dupes.include?(uri) || Repositories.instance.exist?(uri)| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000482-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000482-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 684</span>
684:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scrape</span>(<span class="ruby-identifier">uri</span>)
685:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'open-uri'</span>
686:       <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Scraping #{uri}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
687:       <span class="ruby-identifier">dupes</span> = []
688:       <span class="ruby-identifier">content</span> = <span class="ruby-identifier">open</span>(<span class="ruby-identifier">uri</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
689:         <span class="ruby-keyword kw">begin</span>
690:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/&lt;a[^&gt;]*href=['&quot;]([^'&quot;]*)['&quot;]/</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(svn:\/\/[^&lt;|\n]*)/</span>
691:             <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">$1</span>
692:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\w+:\/\//</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\/plugins\//</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/\/browser\//</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/^http:\/\/wiki\.rubyonrails/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/http:\/\/instiki/</span>
693:               <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">extract_repository_uri</span>(<span class="ruby-identifier">uri</span>)
694:               <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">uri</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">dupes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-operator">||</span> <span class="ruby-constant">Repositories</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">uri</span>)
695:               <span class="ruby-identifier">dupes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">uri</span>
696:             <span class="ruby-keyword kw">end</span>
697:           <span class="ruby-keyword kw">end</span>
698:         <span class="ruby-keyword kw">rescue</span>
699:           <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Problems scraping '#{uri}': #{$!.to_s}&quot;</span>
700:         <span class="ruby-keyword kw">end</span>
701:       <span class="ruby-keyword kw">end</span>
702:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>